package top.infopub.mgr.fia.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Maps;

import top.infopub.generic.GenericDao;
import top.infopub.generic.GenericServiceImpl;
import top.infopub.mgr.fia.dao.FundsAppnDetailDao;
import top.infopub.mgr.fia.domain.FundsAppnDetailDomain;
import top.infopub.model.fia.FundsAppnDetail;
import top.infopub.mgr.fia.service.FundsAppnDetailService;
import top.infopub.mgr.util.DateUtils;

@Service
public class FundsAppnDetailServiceImpl extends GenericServiceImpl<FundsAppnDetail, String> implements
		FundsAppnDetailService {

	@Autowired
	private FundsAppnDetailDao fundsAppnDetailDao;
	
	@Override
	public GenericDao<FundsAppnDetail, String> getDao() {
		return fundsAppnDetailDao;
	}

    @Override
    public Page<FundsAppnDetailDomain> selectDataByWhere(Date monthStart, Date monthEnd,
                                                         String type, String orgId,
                                                         Page<FundsAppnDetailDomain> page) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        Map<String, Object> where = Maps.newHashMap();
        where.put("stsMonthStart", monthStart);
        Date stsMonthEnd = DateUtils.getMonthEnd(monthEnd);
        where.put("stsMonthEnd", stsMonthEnd);       
        where.put("hrOrgBillId", orgId);        
        return (Page<FundsAppnDetailDomain>)fundsAppnDetailDao.selectDataByWhere(where);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteByFundsAppnId(String fundsAppnId) {
       
        fundsAppnDetailDao.deleteByFundsAppnId(fundsAppnId);
        
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addFundsAppnId(List<FundsAppnDetail> fundsAppnDetails) {
        
        if(CollectionUtils.isNotEmpty(fundsAppnDetails)){
            fundsAppnDetailDao.insertByBatch(fundsAppnDetails);
        }
        
    }

}